package com.hnb.controller;

import com.hnb.entity.Register;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import java.util.Map;

@Controller
@RequestMapping("/dev")
public class RegisterController {
    private static final Logger logger = LoggerFactory.getLogger(RegisterController.class);

    // 显示注册页面（GET /register）
    @GetMapping("/register")
    public String showRegisterForm() {
        return "register";  // 返回 register.jsp
    }

    // 处理表单提交（GET /register?username=xxx&password=xxx）
    @PostMapping("/register")
    public String handleRegister(
            @RequestParam("username") String username,
            @RequestParam("password") String password,
            Map<String, Object> model) {
        model.put("username", username);
        model.put("password", password);
        Register register = new Register(username, password);
        model.put("register", register);
        logger.info("表单提交成功，用户名：{}", username);
        return "index";  // 返回 index.jsp
    }
}
